package com.delivery.www.service.ServiceImpl;

import com.delivery.www.dao.UserDao;
import com.delivery.www.po.Ban;
import com.delivery.www.po.User;
import com.delivery.www.util.Md5Utils;
import com.delivery.www.dao.DaoImpl.UserDaoImpl;
import com.delivery.www.service.UserService;

import java.util.List;

/**
 * @author 12970
 */
public class UserServiceImpl implements UserService {
    private final UserDao userDao = new UserDaoImpl();

    @Override
    public User userNameLogin(String userName, String password) {
        if (userName == null || password == null) {
            return null;
        } else {
            String md5Encode = Md5Utils.md5Encode(password);
            return userDao.userNameLogin(userName, md5Encode);
        }
    }

    @Override
    public User emailLogin(String email, String password) {
        if (email == null || password == null) {
            return null;
        } else {
            String md5Encode = Md5Utils.md5Encode(password);
            return userDao.emailLogin(email, md5Encode);
        }
    }

    @Override
    public boolean register(String userName, String password, String email, int identity) {
        if (userName == null || password == null || email == null || identity == 0) {
            return false;
        } else {
            String md5Encode = Md5Utils.md5Encode(password);
            return userDao.register(userName, md5Encode, 0.0F, email, identity) > 0;
        }
    }

    @Override
    public User recharge(int userId, Float value) {
        if (userId <= 0 || value <= 0) {
            return null;
        } else {
            return userDao.recharge(userId, value);
        }
    }

    @Override
    public List<User> getUser() {
        return userDao.getUser();
    }

    @Override
    public List<User> getBanUser(List<Ban> bans) {
        if (bans == null) {
            return null;
        }
        return userDao.getBanUser(bans);
    }

    @Override
    public User getUserById(int userId) {
        if (userId <= 0) {
            return null;
        } else {
            return userDao.getUserById(userId);
        }
    }
}
